package com.tyk.bookstore.back.user.model.vo;

import com.tyk.bookstore.back.system.model.type.MenuType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class RouteVo {

	@Schema(description = "路由名称", requiredMode = Schema.RequiredMode.REQUIRED)
	private String name;

	@Schema(description = "路由路径", requiredMode = Schema.RequiredMode.REQUIRED)
	private String path;

	@Schema(description = "路由组件", requiredMode = Schema.RequiredMode.REQUIRED, nullable = true)
	private String component;

	@Schema(description = "重定向路由地址", requiredMode = Schema.RequiredMode.REQUIRED, nullable = true)
	private String redirect;

	@Schema(description = "路由元信息", requiredMode = Schema.RequiredMode.REQUIRED)
	private Meta meta;

	@Schema(description = "子菜单列表", requiredMode = Schema.RequiredMode.REQUIRED, nullable = true)
	private List<RouteVo> children;

	public void addChild(RouteVo vo) {
		if(this.children==null) this.children = new ArrayList<>();
		this.children.add(vo);
	}

	@Data
	public static class Meta {

		@Schema(description = "菜单标题", requiredMode = Schema.RequiredMode.REQUIRED, nullable = true)
		private String title;

		@Schema(description = "菜单图标", requiredMode = Schema.RequiredMode.REQUIRED, nullable = true)
		private String icon;

		@Schema(description = "菜单类型：0子菜单、1菜单项", requiredMode = Schema.RequiredMode.REQUIRED, type = "integer")
		private MenuType type;

		@Schema(description = "路由隐藏行为: false代表展示, true代表隐藏", requiredMode = Schema.RequiredMode.REQUIRED)
		private Boolean hidden;

		@Schema(description = "是否缓存", requiredMode = Schema.RequiredMode.REQUIRED, nullable = true)
		private Boolean keepAlive;

	}

}
